//
//  ProduceViewController.m
//  ZJControlsClass
//
//  Created by apple on 2024/10/22.
//

#import "ProduceViewController.h"
#import "ProduceNetWorking.h"

#import "ProduceNoDataView.h"
#import "ProduceLongTimeView.h"
#import "ProduceTemporarilyView.h"


@interface ProduceViewController ()

@property (nonatomic,strong) UILabel * titileLabel;



@property (nonatomic,strong) ProduceNoDataView * noDataView; // 没数据
@property (nonatomic,strong) ProduceLongTimeView * longTimeView; // 长期通行证
@property (nonatomic,strong) ProduceTemporarilyView *  TemporarilyView; // 临时

@property (nonatomic,strong) ProduceNetWorking * manager;

@end

@implementation ProduceViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self loadNet];
    [self setUpUI];
    
    
    
    
    
}


-(void)setUpUI{
    
    [self.view addSubview:self.titileLabel];
    
    [self.titileLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).with.offset([[UIApplication sharedApplication]statusBarFrame].size.height);
        make.left.right.equalTo(self.view);
        make.height.equalTo(@(44));
    }];
    
    
    
    
}



-(void)loadNet{
    
    [self.manager dispatchTaskWithParam:@{} completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
        if (responseObject && [responseObject[@"code"] intValue] == 200){
            
            if (![responseObject[@"data"] isKindOfClass:[NSNull class]] && [responseObject[@"data"][@"type"] intValue] == 0){ // type 0 长期  1 零时 code 为1003010019 没得通行证


                // 长期通行证
                [self.view addSubview:self.longTimeView];
                self.longTimeView.paramer = [NSMutableDictionary dictionaryWithDictionary:responseObject[@"data"]];
                [self.longTimeView mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.top.equalTo(self.titileLabel.mas_bottom);
                    make.right.bottom.left.equalTo(self.view);
                }];
                 
            }else if (![responseObject[@"data"] isKindOfClass:[NSNull class]] && [responseObject[@"data"][@"type"] intValue] == 1){ // 临时
                        
                // 临时通行证
                
                __weak typeof(self) weakSelf = self;
                [self.view addSubview:self.TemporarilyView];
                self.TemporarilyView.block = ^(NSString * str) {
                    [weakSelf loadNet];
                };
                self.TemporarilyView.paramer = [NSMutableDictionary dictionaryWithDictionary:responseObject[@"data"]];
                [self.TemporarilyView mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.top.equalTo(self.titileLabel.mas_bottom);
                    make.right.bottom.left.equalTo(self.view);
                }];
                
            }
            
            
        }else if (responseObject && [responseObject[@"code"] intValue] == 1003010019){
         
            
            // 没数据
                [self.view addSubview:self.noDataView];
                [self.noDataView mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.top.equalTo(self.titileLabel.mas_bottom);
                    make.right.bottom.left.equalTo(self.view);
                }];
            
            
        }else{
            [LUtilityTools showAlertWithTitle:@"温馨提示" message:responseObject[@"msg"] buttonAction:^{
                
            }];
        }
    }];
    
}





#pragma mark -- 懒加载

-(UILabel *)titileLabel{
    if (!_titileLabel) {
        _titileLabel = [UILabel new];
        _titileLabel.text = @"示证";
        _titileLabel.textColor = [UIColor blackColor];
        _titileLabel.textAlignment = NSTextAlignmentCenter;
        _titileLabel.font = FONT18;
    }
    return _titileLabel;
}





-(ProduceNoDataView *)noDataView{
    if (!_noDataView){
        _noDataView = [ProduceNoDataView new];
    }
    return _noDataView;
}

-(ProduceLongTimeView *)longTimeView{
    if (!_longTimeView){
        _longTimeView = [ProduceLongTimeView new];
    }
    return _longTimeView;
}

-(ProduceTemporarilyView *)TemporarilyView{
    if (!_TemporarilyView){
        _TemporarilyView = [ProduceTemporarilyView new];
    }
    return _TemporarilyView;
}




-(ProduceNetWorking *)manager{
    if (!_manager){
        _manager = [ProduceNetWorking new];
    }
    return _manager;
}

@end
